//
//  HomeViewController.m
//  mindlook
//
//  Created by reedhong on 11-9-22.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "HomeViewController.h"
#import "LoginViewController.h"
#import "HelpViewController.h"
#import "RequestController.h"


@implementation HomeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        //UIImage* anImage = [UIImage imageNamed:@"MyViewControllerImage.png"];
        UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"Home" image:nil tag:0];
        self.tabBarItem = theItem;
        [theItem release];
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];    
    self.navigationItem.title = NSLocalizedString(@"Home", @"");
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Logout", @"") style:(UIBarButtonItemStyleBordered) target:self action:@selector(logout:)];
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)logout:(id)sender 
{
    NSString* result = [[RequestController sharedInstance] logout];
    
    NSLog(@"logout result: %@", result);
    
    LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:loginViewController animated: YES]; 
    [loginViewController release];
}

- (IBAction)help:(id)sender
{
    HelpViewController *helpViewController = [[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:helpViewController animated: YES]; 
    [helpViewController release];        

}

@end
